package elastic

import (
	"chatgpt/helper"
)

func Init() {
	logtt = &logt{}
	Client = NewSearch(GetMainIndexConfig())
	ClientFile = NewSearchFile(GetFileIndexConfig())
}

// 主记录集 对应ES 数据index 表
func GetMainIndexConfig() (string, string) {
	index := CONST_WENDA_INDEX
	cnf := helper.Config().Sub("elastic")
	if cnf.GetString("index") != "" {
		index = cnf.GetString("index")
	}
	mapping := `{
		"settings":{
			"number_of_shards":1,
			"number_of_replicas":0
		},
		"mappings": {
			"properties":{
				"id":{"type":"integer"},
				"prompt":{
					"type":"text",
					"analyzer":"ik_max_word",
					"search_analyzer" : "ik_max_word"
				},
				"scope":{"type":"integer"},
				"content":{"type":"text"}
			}
		}
}`
	return index, mapping
}

// 对应数据集记录表
func GetFileIndexConfig() (string, string) {
	index := CONST_WENDA_INDEX
	cnf := helper.Config().Sub("elastic")
	if cnf.GetString("index") != "" {
		index = cnf.GetString("index")
	}
	index += "_files"
	mapping := `{
		"settings":{
			"number_of_shards":1,
			"number_of_replicas":0
		},
		"mappings": {
			"properties":{
				"created_at": {"type":"text"},
                "file_full_name": {
					"type":"text",
					"analyzer":"ik_max_word",
					"search_analyzer" : "ik_max_word"
				},
                "file_name": {
					"type":"text",
					"analyzer":"ik_max_word",
					"search_analyzer" : "ik_max_word"
				},
                "file_suffix": {"type":"text"},
                "total": {"type":"integer"},
                "updated_at": {"type":"text"},
				"md5": {
					"type":"text",
					"analyzer":"ik_max_word",
					"search_analyzer" : "ik_max_word"
				},
				"scope":{"type":"integer"},
			}
		}
}`
	return index, mapping
}
